package com.roc.web.action.estrn;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Role;

public class YsbTransSumSearchCondition extends BaseSearchCondition{

	private static final long serialVersionUID = 3836483817904214306L;
	private String minDate;		
	private String maxDate;		
	private String merNo;  //商户号		
	private String merName;  //商户名		
    private String opId;		
	private String agentId;		
	private String marketorId;
	private String ucbccdArea;		
	private String sn;
	private String roleType;//角色类型
	private String phNo;
	private String isFull;
	private String certifNo;
	private String termType;

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		
		return " order by t.mcht_cd ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		if (roleType.equals(Role.AGENT.getCode() )||roleType.equals(Role.SFB_AGENT.getCode() )||roleType.equals(Role.O_MANAGER.getCode())) {
			sb = sb.append(" select count(1) ")
					.append(" from tbl_activity_sum t,tbl_mcht_inf tm,t_pos_info b,t_pos_agent a,tbl_mcht_bankaccount c ")
					.append(" where t.mcht_cd = tm.mcht_cd and t.mcht_cd = b.merc_code and t.serial_num = b.serial_num  and t.mcht_cd = c.owner_cd ")
					.append(" and c.accounttype = '01'  and b.serial_num = a.serial_num and b.pos_brand = a.pos_brand and tm.group_cd='3' and  a.agent_id=").append(agentId);
		}else if(roleType.equals(Role.MARKET_DIRECT.getCode()) || roleType.equals(Role.MARKET_LEAD.getCode())){//销售人员
			sb = sb.append(" select count(1) ")
					.append(" from tbl_activity_sum t,tbl_mcht_inf tm,t_pos_info b,tbl_mcht_bankaccount c ")
					.append(" where t.mcht_cd = tm.mcht_cd and t.mcht_cd = b.merc_code  and t.serial_num = b.serial_num ")
					.append(" and t.mcht_cd = c.owner_cd and c.accounttype = '01' and tm.group_cd='3' and  exists (select 1 from t_oper_role tor where tm.uc_bc_cd_area = tor.agentid and tor.operid ="+marketorId+") ");
		}else{
			sb = sb.append(" select count(1) ")
					.append(" from tbl_activity_sum t,tbl_mcht_inf tm,t_pos_info b,tbl_mcht_bankaccount c ")
					.append(" where t.mcht_cd = tm.mcht_cd and t.mcht_cd = b.merc_code  and t.serial_num = b.serial_num ")
					.append(" and t.mcht_cd = c.owner_cd and c.accounttype = '01' and tm.group_cd='3' ");
 
		}

		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		if (roleType.equals(Role.AGENT.getCode() )||roleType.equals(Role.SFB_AGENT.getCode() )||roleType.equals(Role.O_MANAGER.getCode())) {
			sb = sb.append(" select t.mcht_cd,tm.contact_phoneno,tm.name_busi, ")
					.append(" tm.certif_no,b.asset_flag,c.account,t.remark1, ")
					.append(" t.remark2,t.trans_at, t.is_success,to_char(t.bind_date,'yyyymmdd HH24:mi:ss'), t.serial_num,t.des_date,t.des_amt  ")
					.append(" from tbl_activity_sum t,tbl_mcht_inf tm,t_pos_info b,t_pos_agent a,tbl_mcht_bankaccount c ")
					.append(" where t.mcht_cd = tm.mcht_cd and t.mcht_cd = b.merc_code and t.serial_num = b.serial_num  and t.mcht_cd = c.owner_cd ")
					.append(" and c.accounttype = '01'  and b.serial_num = a.serial_num and b.pos_brand = a.pos_brand and tm.group_cd='3' and  a.agent_id=").append(agentId);
		}else if(roleType.equals(Role.MARKET_DIRECT.getCode()) || roleType.equals(Role.MARKET_LEAD.getCode())){//销售人员
			sb = sb.append(" select t.mcht_cd, tm.contact_phoneno, tm.name_busi,tm.certif_no, b.asset_flag, ")
					.append(" c.account,t.remark1, t.remark2,t.trans_at,t.is_success,to_char(t.bind_date,'yyyymmdd HH24:mi:ss'), t.serial_num,t.des_date,t.des_amt ")
					.append(" from tbl_activity_sum t,tbl_mcht_inf tm,t_pos_info b,tbl_mcht_bankaccount c ")
					.append(" where t.mcht_cd = tm.mcht_cd and t.mcht_cd = b.merc_code  and t.serial_num = b.serial_num ")
					.append(" and t.mcht_cd = c.owner_cd and c.accounttype = '01' and tm.group_cd='3' and  exists (select 1 from t_oper_role tor where tm.uc_bc_cd_area = tor.agentid and tor.operid ="+marketorId+") ");
		}else{
			sb = sb.append(" select t.mcht_cd, tm.contact_phoneno, tm.name_busi,tm.certif_no, b.asset_flag, ")
					.append(" c.account,t.remark1, t.remark2,t.trans_at,t.is_success,to_char(t.bind_date,'yyyymmdd HH24:mi:ss'), t.serial_num,t.des_date,t.des_amt ")
					.append(" from tbl_activity_sum t,tbl_mcht_inf tm,t_pos_info b,tbl_mcht_bankaccount c ")
					.append(" where t.mcht_cd = tm.mcht_cd and t.mcht_cd = b.merc_code  and t.serial_num = b.serial_num ")
					.append(" and t.mcht_cd = c.owner_cd and c.accounttype = '01' and tm.group_cd='3' ");
 
		}
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		//商户号
		if (Constance.isNotEmpty(merNo)) {
			filedBeanList.add(new WhereHQLFieldBean("t.mcht_cd", merNo.trim(), "=", false));
		}
		
		/*if (Constance.isNotEmpty(merName)) {
			
			filedBeanList.add(new WhereHQLFieldBean("tm.NAME_BUSI", merName.trim(),"LIKE", false, "ALL"));
		}*/
		
		if(Constance.isNotEmpty(sn)){
			filedBeanList.add(new WhereHQLFieldBean("t.serial_num", sn.trim(), "=", false));
		}
		
		if(Constance.isNotEmpty(isFull)){
			filedBeanList.add(new WhereHQLFieldBean("t.is_success", isFull.trim(), "=", false));
		}
		
		//终端类型
		if(Constance.isNotEmpty(termType)){
			filedBeanList.add(new WhereHQLFieldBean("b.asset_flag", termType.trim(), "=", false));
		}
		
		//身份证号码
		if(Constance.isNotEmpty(certifNo)){
			filedBeanList.add(new WhereHQLFieldBean("tm.certif_no", certifNo.trim(), "=", false));
		}
		
		//手机号码
		if(Constance.isNotEmpty(phNo)){
			filedBeanList.add(new WhereHQLFieldBean("tm.contact_phoneno", phNo.trim(), "=", false));
		}
		
		if(Constance.isNotEmpty(opId)){//操作员 
	    	filedBeanList.add(new WhereHQLFieldBean("tm.rec_upd_opr", opId.trim(), "=", false));
	    }
		
		if(Constance.isNotEmpty(minDate)){
			filedBeanList.add(new WhereHQLFieldBean("t.bind_date >= to_date('"+minDate.trim()+"', 'yyyymmdd')"));
         	
       	}
		
		if(Constance.isNotEmpty(maxDate)){
			filedBeanList.add(new WhereHQLFieldBean("t.bind_date < to_date('"+maxDate.trim()+"', 'yyyymmdd' )+1 "));
       	}
		
		return filedBeanList;
	}


	public String getMerNo() {
		return merNo;
	}

	public void setMerNo(String merNo) {
		this.merNo = merNo;
	}

	public String getMerName() {
		return merName;
	}

	public void setMerName(String merName) {
		this.merName = merName;
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getOpId() {
		return opId;
	}

	public void setOpId(String opId) {
		this.opId = opId;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getMarketorId() {
		return marketorId;
	}

	public void setMarketorId(String marketorId) {
		this.marketorId = marketorId;
	}

	public String getUcbccdArea() {
		return ucbccdArea;
	}

	public void setUcbccdArea(String ucbccdArea) {
		this.ucbccdArea = ucbccdArea;
	}

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

	public String getPhNo() {
		return phNo;
	}

	public void setPhNo(String phNo) {
		this.phNo = phNo;
	}

	public String getIsFull() {
		return isFull;
	}

	public void setIsFull(String isFull) {
		this.isFull = isFull;
	}

	public String getCertifNo() {
		return certifNo;
	}

	public void setCertifNo(String certifNo) {
		this.certifNo = certifNo;
	}

	public String getTermType() {
		return termType;
	}

	public void setTermType(String termType) {
		this.termType = termType;
	}
	
	


}
